package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
)

/**
 * 控制台中读数据操作实例1，输入stop停止
 */
func Reader1() {
	running := true
	reader := bufio.NewReader(os.Stdin)
	for running {
		fmt.Println("Please input the string...")
		data, _, _ := reader.ReadLine()
		fmt.Println("The data is ", data)
		command := string(data)
		if command == "stop" {
			running = false
		}
		log.Println("The command string is:", command)
	}
}

/**
 * 控制台读取数据操作2，只能读取整数或一个字符，并不能用空格分割
 */
func Reader2() {
	var i int
	fmt.Println("Please input the num:")
	_, err := fmt.Scanf("%d", &i)
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("The i is:%d\n", i)
}

func Reader3() {
	fmt.Println("Welcome to use Reader3...")
	scanner := bufio.NewScanner(os.Stdin)
	for { //看作是一个while循环
		fmt.Println("Please input the string...")
		scanner.Scan()
		if scanner.Text() == "stop" {
			fmt.Println("Your input string is:", scanner.Text())
			break
		}
		fmt.Println("Your input string is:", scanner.Text())
	}
}

func main() {
	Reader1()
	Reader2()
	Reader3()
	var s string
	var t string
	fmt.Scanln(&s)
	fmt.Scanln(&t)
	fmt.Println(s)
	fmt.Println(t)
}
